﻿<Window x:Class="AnthStat.WPF.Presentation.AnthStatWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:p="clr-namespace:AnthStat.WPF.Presentation.Properties"
        xmlns:viewmodels="clr-namespace:AnthStat.WPF.Applications;assembly=AnthStat.WPF.Applications"
        xmlns:controls="clr-namespace:AnthStat.WPF.Presentation.Controls"
        mc:Ignorable="d" 
        SnapsToDevicePixels="True"
        Title="AnthStat" 
        MinWidth="960"
        MinHeight="700"
        Height="800"
        Width="1150"
        Closing="Window_Closing"
        d:DesignHeight="700" d:DesignWidth="1000">
    <Window.Resources>
        <viewmodels:DesignProjectViewModel x:Key="DesignViewModel" />
    </Window.Resources>
    <Window.DataContext>
        <viewmodels:FileScreenViewModel />
    </Window.DataContext>
    <Grid>
        <Grid d:DataContext="{StaticResource DesignViewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <Grid Grid.Row="0" Background="{StaticResource AccentBrush}">
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

                <StackPanel Orientation="Horizontal">
                    <Button Style="{StaticResource BlankButtonStyle}" x:Name="btnOptions"
                            Click="btnOptions_Click"
                        Margin="20, 0, 10, 0" >
                        <Button.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Export to CSV" Command="{Binding ExportToCSVCommand}" />
                                <MenuItem Header="Close Project" Command="{Binding PromptCloseProjectCommand}" />
                            </ContextMenu>
                        </Button.ContextMenu>
                        <Path 
                        Fill="White"
                        Stretch="Fill"
                        Height="28"
                        Width="28"
                        Data="F1 M 19,23L 27,23L 27,31L 19,31L 19,23 Z M 19,34L 27,34L 27,42L 19,42L 19,34 Z M 31,23L 57,23L 57,31L 31,31L 31,23 Z M 19,45L 27,45L 27,53L 19,53L 19,45 Z M 31,34L 57,34L 57,42L 31,42L 31,34 Z M 31,45L 57,45L 57,53L 31,53L 31,45 Z "></Path>
                    </Button>
                    
                    <TextBlock Foreground="White" VerticalAlignment="Center" Margin="20, 10, 0, 10" FontSize="24" Text="{Binding CurrentProject.Name}" />
                </StackPanel>


                <Grid Grid.Column="1" Margin="30, 0, 30, 0" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="TxtGenericSearchBox" Grid.Column="0" BorderBrush="White" FontSize="16" Padding="3" Width="300">
                        <TextBox.InputBindings>
                            <KeyBinding Command="{Binding Path=CurrentProject.SearchChildrenCommand}" CommandParameter="{Binding ElementName=TxtGenericSearchBox, Path=Text}" Key="Return"/>
                            <KeyBinding Command="{Binding Path=CurrentProject.SearchChildrenCommand}" CommandParameter="" Key="Escape"/>
                        </TextBox.InputBindings>
                    </TextBox>
                    <Button Grid.Column="1" Style="{StaticResource DarkButtonStyle}" Command="{Binding CurrentProject.SearchChildrenCommand}" CommandParameter="{Binding ElementName=TxtGenericSearchBox, Path=Text}" Content="search" FontWeight="SemiBold" Foreground="Black" Padding="12, 4, 12, 4" Background="Gold" />
                </Grid>

                <StackPanel Grid.Column="2" Orientation="Horizontal" Margin="0, 4, 0, 4">
                <Button Style="{StaticResource BlankButtonStyle}" 
                        Margin="20, 0, 40, 0"
                        DataContext="{StaticResource SettingsViewModel}"
                        Command="{Binding ToggleShowSettingsCommand}">
                    <Path 
                        Fill="White"
                        Stretch="Fill"
                        Height="28"
                        Width="28"
                        Data="F1 M 38,23.5C 38.8643,23.5 39.7109,23.5756 40.5337,23.7206L 42.6275,18.5381L 48.1901,20.787L 46.0964,25.9692C 47.6473,27.0149 48.9851,28.3527 50.0308,29.9036L 55.213,27.8099L 57.4619,33.3725L 52.2794,35.4664C 52.4244,36.2891 52.5,37.1357 52.5,38C 52.5,38.8643 52.4244,39.7109 52.2794,40.5337L 57.4619,42.6275L 55.213,48.1901L 50.0308,46.0964C 49.0795,47.5073 47.8865,48.7418 46.5112,49.7405L 48.7844,54.8462L 43.3041,57.2891L 41.0307,52.1828C 40.0533,52.3906 39.0394,52.5 38,52.5C 37.1357,52.5 36.2891,52.4244 35.4664,52.2794L 33.3725,57.462L 27.8099,55.213L 29.9036,50.0309C 28.3527,48.9851 27.0149,47.6473 25.9691,46.0964L 20.787,48.1901L 18.538,42.6275L 23.7206,40.5336C 23.5756,39.7109 23.5,38.8643 23.5,38C 23.5,37.1357 23.5756,36.2891 23.7206,35.4664L 18.538,33.3725L 20.787,27.8099L 25.9691,29.9036C 26.9205,28.4927 28.1135,27.2582 29.4889,26.2594L 27.2157,21.1537L 32.6959,18.7109L 34.9694,23.8172C 35.9468,23.6094 36.9606,23.5 38,23.5 Z M 38,28C 32.4771,28 28,32.4772 28,38C 28,43.5229 32.4771,48 38,48C 43.5228,48 48,43.5229 48,38C 48,32.4772 43.5228,28 38,28 Z "></Path>
                </Button>
            </StackPanel>
        </Grid>
            <controls:NutritionalSurveyView Grid.Row="2" DataContext="{Binding CurrentProject}" Visibility="{Binding DataCaptureMode, Converter={StaticResource DataCaptureModeToVisibilityConverter}, ConverterParameter='NS'}" />
            <controls:IndividualAssessmentsView Grid.Row="2" DataContext="{Binding CurrentProject}" Visibility="{Binding DataCaptureMode, Converter={StaticResource DataCaptureModeToVisibilityConverter}, ConverterParameter='IA'}" />

            <controls:SettingsPanel Grid.Row="0" Grid.RowSpan="3" Grid.ColumnSpan="3" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0, 5, 20, 0" DataContext="{StaticResource SettingsViewModel}" Visibility="{Binding IsShowingSettingsPanel, Converter={StaticResource BooleanToVisibilityConverter}}" />

            <Grid Background="#33000000" DataContext="{Binding CurrentProject}"
              Grid.Row="0" 
              Visibility="{Binding ChildrenView.CurrentItem.MeasurementsView.CurrentItem.IsShowingIndividualChart, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}"
              Grid.ColumnSpan="3" 
              Grid.RowSpan="3" >
            <Border Margin="0" Padding="10" Background="{StaticResource AccentBrush}">
            <Border Padding="10" Background="White">
            <Grid Grid.Row="1" Height="Auto" >
                <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*" />
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                    
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                    <Grid Grid.Row="0" Grid.ColumnSpan="4" Margin="0, 0, 0, 20">

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                        
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <StackPanel Grid.Row="0" Grid.Column="1">
                                <Button Style="{StaticResource DarkButtonStyle}" Background="Tomato" Command="{Binding ChildrenView.CurrentItem.MeasurementsView.CurrentItem.ToggleShowIndividualChartCommand}">
                                    <Path Margin="2" Width="14" Height="14" Stretch="Fill" Fill="White" Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z "/>
                                </Button>

                            </StackPanel>
                        
                            <StackPanel Orientation="Horizontal">
                                <ComboBox x:Name="cmbChartIndicator" Width="200" SelectedIndex="0" ItemsSource="{StaticResource IndicatorChartArray}" 
                                          SelectedValuePath="ValueString"
                                          DisplayMemberPath="DisplayString" />

                                    <StackPanel Width="20" />

                                <ComboBox x:Name="cmbCurveType" Width="150" SelectedIndex="0" ItemsSource="{StaticResource CurveTypeArray}" 
                                          SelectedValuePath="ValueString"
                                          DisplayMemberPath="DisplayString" />

                                <StackPanel Width="20" />

                                <TextBlock VerticalAlignment="Center" Margin="0, 0, 4, 0" Text="X-Axis range:" />
                                <controls:NumericTextBox x:Name="txtXAxisStart" Text="0" Padding="2" HorizontalContentAlignment="Right" VerticalAlignment="Center" Width="32" />
                                <TextBlock VerticalAlignment="Center" Margin="4, 0, 4, 0" Text="to" />
                                <controls:NumericTextBox x:Name="txtXAxisEnd" Text="21" Padding="2" HorizontalContentAlignment="Right" VerticalAlignment="Center" Width="32" />
                            </StackPanel>

                            <StackPanel Grid.Row="1" Grid.ColumnSpan="2" Height="1" Background="#CCCCCC" VerticalAlignment="Top" Margin="0, 10, 0, 0" />

                            <StackPanel Grid.Row="1" Margin="0, 15, 0, 0">
                                <TextBlock Margin="0, 0, 0, 5" Text="{Binding ElementName=cmbChartIndicator, Path=Text}" FontSize="24" FontWeight="Bold" />
                                <TextBlock Margin="0, 0, 0, 0" Text="WHO Child Growth Standards / WHO Reference 2007" Foreground="#444444" FontSize="16" FontWeight="Normal"  Visibility="{Binding Source={x:Static p:Settings.Default}, Path=PrimaryGrowthReference, Mode=OneWay, Converter={StaticResource GrowthReferenceToVisibilityConverter}, ConverterParameter='WHO'}" />
                                <TextBlock Margin="0, 0, 0, 0" Text="CDC Growth Reference 2000" Foreground="#444444" FontSize="16" FontWeight="Normal"  Visibility="{Binding Source={x:Static p:Settings.Default}, Path=PrimaryGrowthReference, Mode=OneWay, Converter={StaticResource GrowthReferenceToVisibilityConverter}, ConverterParameter='CDC'}" />
                            </StackPanel>
                        </Grid>

                        <controls:IndicatorChartControl 
                            YAxisStartValue="{Binding ElementName=cmbChartIndicator, Path=SelectedValue, Converter={StaticResource ChartMeasurementToYAxisStartConverter}}"
                            
                                    
                                    XAxisStartValue="{Binding ElementName=txtXAxisStart, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    XAxisEndValue="{Binding ElementName=txtXAxisEnd, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                            
                            ShowsInPercentiles="{Binding ElementName=cmbCurveType, Path=SelectedValue, Converter={StaticResource CurveTypeToBooleanConverter}}"
                        
                        YAxisLabel="{Binding ElementName=cmbChartIndicator, Path=SelectedValue}"
                        XAxisLabel="Age (months)"
                        
                        YAxisPath="{Binding ElementName=cmbChartIndicator, Path=SelectedValue}"
                        XAxisPath="AgeYears"
                                    
                                    DataContext="{Binding ChildrenView.CurrentItem}" 
                                    ItemsSource="{Binding MeasurementsView}" 
                                    GrowthReference="{Binding Source={x:Static p:Settings.Default}, Path=PrimaryGrowthReference}"
                                    
                                    Grid.Row="1" 
                                    Grid.Column="2" >
                            <controls:IndicatorChartControl.YAxisStepValue>
                                <MultiBinding Converter="{StaticResource ChartYAxisStepConverter}" >
                                    <Binding RelativeSource="{RelativeSource Mode=Self}" Path="YAxisStartValue" />
                                    <Binding RelativeSource="{RelativeSource Mode=Self}" Path="YAxisEndValue" />
                                </MultiBinding>
                            </controls:IndicatorChartControl.YAxisStepValue>

                            <controls:IndicatorChartControl.YAxisEndValue>
                                <MultiBinding Converter="{StaticResource ChartMeasurementToYAxisEndMultiConverter}" >
                                    <Binding ElementName="cmbChartIndicator" Path="SelectedValue" />
                                    <Binding Source="{x:Static p:Settings.Default}" Path="PrimaryGrowthReference" />
                                </MultiBinding>
                            </controls:IndicatorChartControl.YAxisEndValue>
                        </controls:IndicatorChartControl>
               
            </Grid>
            </Border>
            </Border>
        </Grid>


        <Grid DataContext="{Binding CurrentProject}" Visibility="{Binding IsShowingRemovePersonPrompt, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" 
              Background="#33000000"
              Grid.Row="0" 
              Grid.ColumnSpan="3" 
              Grid.RowSpan="3" >
            <controls:MessageBox 
                Title="Confirm deletion" 
                MessageBoxButton="YesNo" 
                AcceptCommand="{Binding RemovePersonCommand}"
                CancelCommand="{Binding PromptRemovePersonCommand}"
                RejectCommand="{Binding PromptRemovePersonCommand}"
                Content="Are you sure you wish to delete this child? Any measurements associated with this child will also be removed. This action cannot be undone." />
        </Grid>

            <Grid DataContext="{Binding CurrentProject}" Visibility="{Binding ChildrenView.CurrentItem.IsShowingRemoveMeasurementPrompt, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" 
              Background="#33000000"
              Grid.Row="0" 
              Grid.ColumnSpan="3" 
              Grid.RowSpan="3" >
                <controls:MessageBox 
                Title="Confirm deletion" 
                MessageBoxButton="YesNo" 
                AcceptCommand="{Binding ChildrenView.CurrentItem.RemoveMeasurementCommand}"
                CancelCommand="{Binding ChildrenView.CurrentItem.PromptRemoveMeasurementCommand}"
                RejectCommand="{Binding ChildrenView.CurrentItem.PromptRemoveMeasurementCommand}"
                Content="Are you sure you wish to delete this measurement? This action cannot be undone." />
            </Grid>

            <Grid DataContext="{Binding}" Visibility="{Binding IsShowingSaveProjectPrompt, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" 
                      Background="#33000000"
                      Grid.Row="0" 
                      Grid.ColumnSpan="3" 
                      Grid.RowSpan="3" >
                <controls:MessageBox 
                        Title="Save changes?" 
                        MessageBoxButton="YesNoCancel" 
                        AcceptCommand="{Binding CloseAndSaveProjectCommand}"
                        CancelCommand="{Binding CancelCloseProjectCommand}"
                        RejectCommand="{Binding CloseProjectCommand}"
                        Content="Do you wish to save your changes to this project before closing?" />
            </Grid>

            <Grid DataContext="{Binding CurrentProject}" Visibility="{Binding IsShowingNewPersonPrompt, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" 
              Background="#33000000"
              Grid.Row="0" 
              Grid.ColumnSpan="3" 
              Grid.RowSpan="3" >
                <controls:NewPerson Width="400" Height="240" />
            </Grid>

        </Grid>

        <Border DataContext="{Binding}" Background="White"  Visibility="{Binding CurrentProject, Converter={StaticResource NullToCollapsedConverter}, FallbackValue=Collapsed}">
            <controls:MainMenu />
        </Border>

        <Grid DataContext="{Binding CurrentProject}" Visibility="{Binding IsShowingProjectLoadScreen, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" 
                      Background="#33000000">
            <controls:LoadingScreen 
                Title="Project load progress" 
                Progress="{Binding ProjectLoadProgress}"
                Message="{Binding ProjectLoadStatus}" />
        </Grid>

        <Grid DataContext="{Binding CsvExporterViewModel}" Visibility="{Binding IsDisplaying, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" 
                      Background="#33000000">
            <controls:CsvExporter Width="600" Height="200" />
        </Grid>

    </Grid>
</Window>
